﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace Home.Haushalt
{
    #region ENUMS

    /// <summary></summary>
    public enum ActionResult
    {
        /// <summary></summary>
        Ok = 0,
        /// <summary></summary>
        Hinweis = 1,
        /// <summary></summary>
        Nok = 2
    }

    /// <summary>
    /// 
    /// </summary>
    public enum ActionType
    {
        /// <summary>per Hand erzeugt</summary>
        Dev,
        /// <summary>Events vom Sql-Server</summary>
        SqlExecute,
        /// <summary>Events vom Sql-Server</summary>
        SqlMessage,
        /// <summary>Events vom Sql-Server</summary>
        SqlScript
    }

    #endregion ENUMS

    /// <summary>
    /// 
    /// </summary>
    public class Journal : IDisposable
    {

        #region DISPOSABLE SUPPORTING

        /// <summary>Dispose</summary>
        ~Journal()
        {
            Dispose(false);
        }

        /// <summary>
        /// Dispose
        /// </summary>
        /// <param name="disposing"></param>
        protected void Dispose(bool disposing)
        {
            if (!Enabled)
                return;

            if (disposing)
            {
                Journal.WriteEnd();
            }

            Journal._depth--;

            if (Compress && Journal._depth < 0)
            {
                try
                {
                    CreateZipFile(_logFullFileName, Path.Combine(Path.GetDirectoryName(_logFullFileName), Path.GetFileNameWithoutExtension(_logFullFileName)) + ".gz");

                    try
                    {
                        File.Delete(_logFullFileName);
                    }
                    catch { }
                }
                catch { }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            Dispose(true);

            GC.SuppressFinalize(this);
        }

        #endregion DISPOSABLE SUPPORTING

        #region STATIC METHODS AND PROPERTIES

        /// <summary>
        /// 
        /// </summary>
        public class ActionResultEscalationEventArgs : EventArgs
        {
            /// <summary></summary>
            public string Action = "";
            /// <summary></summary>
            public ActionResult ActionResult = ActionResult.Ok;

            /// <summary>
            /// 
            /// </summary>
            /// <param name="action"></param>
            /// <param name="actionResult"></param>
            public ActionResultEscalationEventArgs(string action, ActionResult actionResult)
            {
                Action = action;
                ActionResult = actionResult;
            }
        }

        /// <summary></summary>
        public static event EventHandler<ActionResultEscalationEventArgs> OnActionResultEscalation;

        #region CONSTANTS

        /// <summary></summary>
        public const string COLUMNNAME_SENDER = "colSender";
        /// <summary></summary>
        public const string COLUMNNAME_TIME = "colTime";
        /// <summary></summary>
        public const string COLUMNNAME_ACTIONTYPE = "colActionType";
        /// <summary></summary>
        public const string COLUMNNAME_ACTION = "colAction";
        /// <summary></summary>
        public const string COLUMNNAME_ACTIONRESULT = "colActionResult";
        /// <summary></summary>
        public const string COLUMNNAME_COMMENTS = "colComments";
        /// <summary></summary>
        public const string COLUMNNAME_EXCEPTION = "colException";


        /// <summary></summary>
        public const string JOURNALTAG_ACTION = "act";
        /// <summary></summary>
        public const string JOURNALTAG_STEP = "step";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_MODUL = "modul";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_TIME = "time";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_RESULT = "res";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_NOTE = "note";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_TYPE = "type";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_SETUPAPPVERSION = "setupAppVersion";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_SETUPFILEVERSION = "setupFileVersion";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_SUMMARY = "summary";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_TOTALERRORCOUNT = "totalErrorCount";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_TOTALWARNINGCOUNT = "totalWarningCount";
        /// <summary></summary>
        public const string JOURNALATTRIBUT_TOTALRUNTIME = "totalRunTime";

        #endregion CONSTANTS

        #region SUPPORT METHODS

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lpSourceFile"></param>
        /// <param name="lpZipFile"></param>
        private static void CreateZipFile(string lpSourceFile, string lpZipFile)
        {
            if (File.Exists(lpSourceFile))
            {
                /*Byte[] datei = File.ReadAllBytes(lpSourceFile);
                using (GZipStream gzipStream = new GZipStream(new FileStream(lpZipFile, System.IO.FileMode.Create), CompressionMode.Compress))
                {
                    foreach (Byte byt in datei)
                    {
                        gzipStream.WriteByte(byt);
                    }
                }*/


                /*//var filesToZip = new DirectoryInfo(@"c:\Test\").GetFiles("*.txt").Select(p => p.FullName);
                List<string> filesToZip = new List<string>();
                filesToZip.Add(lpSourceFile);
                using (Package exportPackage = Package.Open(lpZipFile))
                {
                    
                    foreach (var file in filesToZip)
                        using (FileStream fileStream = File.OpenRead(file))
                        {
                            Uri partUriDocument = PackUriHelper.CreatePartUri(new Uri(Path.GetFileName(file), UriKind.Relative));
                            PackagePart packagePart = exportPackage.CreatePart(partUriDocument, System.Net.Mime.MediaTypeNames.Text.Plain);
                            CopyStream(fileStream, packagePart.GetStream());
                        }
                }*/


                byte[] buffer;
                int count = 0;
                FileStream fsOut = null;
                FileStream fsIn = null;
                GZipStream gzip = null;

                try
                {
                    fsOut = new FileStream(lpZipFile, FileMode.Create, FileAccess.Write, FileShare.None);
                    gzip = new GZipStream(fsOut, CompressionMode.Compress, true);
                    fsIn = new FileStream(lpSourceFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                    buffer = new byte[fsIn.Length];
                    count = fsIn.Read(buffer, 0, buffer.Length);
                    fsIn.Close();
                    fsIn = null;
                    gzip.Write(buffer, 0, buffer.Length);
                }
                catch
                {
                }
                finally
                {
                    if (gzip != null)
                    {
                        gzip.Close();
                        gzip = null;
                    }
                    if (fsOut != null)
                    {
                        fsOut.Close();
                        fsOut = null;
                    }
                    if (fsIn != null)
                    {
                        fsIn.Close();
                        fsIn = null;
                    }
                }
            }
        }

        /* private static void CopyStream(Stream source, Stream target)
         {
             const int bufSize = 0x1000;
             byte[] buf = new byte[bufSize];
             int bytesRead = 0;
             while ((bytesRead = source.Read(buf, 0, bufSize)) > 0)
                 target.Write(buf, 0, bytesRead);
         }*/



        /// <summary>
        /// 
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private static string ConvertToXmlString(string text)
        {
            text = text.Replace("<", "&lsaquo;");
            text = text.Replace(">", "&rsaquo;");
            text = text.Replace("\"", "&quot;");
            text = text.Replace("&", "&amp;");
            return text;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tabCount"></param>
        /// <returns></returns>
        private static string GetTabs(int tabCount)
        {
            string result = "";

            for (int i = 0; i < tabCount; i++)
                result += '\t';
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="tiefe"></param>
        /// <returns></returns>
        private static string GetInnerException(Exception ex, int tiefe)
        {
            if (ex == null)
                return "";

            string result = ex.Message;
            if (ex.InnerException != null && tiefe < 10)
            {
                result += "\n\n" + ex.InnerException.Message;
                result += GetInnerException(ex.InnerException, ++tiefe);
            }
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private static string GetSenderName(object sender)
        {
            string sendername = "";
            if (sender != null)
            {
                if (sender is Type)
                    sendername = ((Type)sender).FullName;
                else
                    sendername = sender.GetType().Name;
            }
            return sendername;
        }

        #endregion SUPPORT METHODS

        #region ADD POLYMORPHE

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static string Add(object sender, string comment)
        {
            return Add(sender, ActionType.Dev, "", ActionResult.Ok, comment, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="action"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static string Add(object sender, string action, string comment)
        {
            return Add(sender, ActionType.Dev, action, ActionResult.Ok, comment, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="actionResult"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static string Add(object sender, ActionResult actionResult, string comment)
        {
            return Add(sender, ActionType.Dev, "", actionResult, comment, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="action"></param>
        /// <param name="actionResult"></param>
        /// <param name="comments"></param>
        /// <returns></returns>
        public static string Add(object sender, string action, ActionResult actionResult, string comments)
        {
            return Add(sender, ActionType.Dev, action, actionResult, comments, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="action"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static string Add(object sender, string action, Exception ex)
        {
            return Add(sender, ActionType.Dev, action, ActionResult.Nok, action, ex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="actionResult"></param>
        /// <param name="action"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static string Add(object sender, ActionResult actionResult, string action, Exception ex)
        {
            return Add(sender, ActionType.Dev, action, actionResult, "", ex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static string Add(object sender, Exception ex)
        {
            return Add(sender, ActionType.Dev, "", ActionResult.Nok, "", ex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="actionType"></param>
        /// <param name="action"></param>
        /// <param name="actionResult"></param>
        /// <param name="comments"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static string Add(object sender, ActionType actionType, string action, ActionResult actionResult, string comments, Exception ex)
        {
            if (!Enabled)
                return "";

            return Write(GetSenderName(sender), actionType, action, actionResult, comments, (ex != null) ? ex.Message + "; " + ex.Source + "; " + ex.StackTrace + "; " + GetInnerException(ex, 0) : "");
        }

        #endregion ADD POLYMORPHE

        #region LABEL TRANACTION

        /// <summary></summary>
        private static List<DataTable> _transactTables = new List<DataTable>();

        /// <summary></summary>
        public static event EventHandler OnLabelModified;

        /// <summary></summary>
        public static List<string> Labels
        {
            get
            {
                List<string> labels = new List<string>();
                foreach (DataTable tbl in _transactTables)
                {
                    labels.Add(tbl.TableName);
                }
                return labels;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="labelName"></param>
        public static void SetLabel(string labelName)
        {
            DataTable tbl = GetLabel(labelName);
            if (tbl != null)
            {
                _transactTables.Remove(tbl);
            }

            tbl = _logTable.Copy();
            tbl.TableName = labelName;
            _transactTables.Add(tbl);

            if (OnLabelModified != null)
                OnLabelModified(labelName, new EventArgs());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="labelName"></param>
        public static void RollbackTo(string labelName)
        {
            DataTable tbl = GetLabel(labelName);
            if (tbl != null)
            {
                _logTable.Rows.Clear();
                foreach (DataRow row in tbl.Rows)
                {
                    _logTable.ImportRow(row);
                }

                while ((_transactTables.Count - 1) > _transactTables.IndexOf(tbl))
                    _transactTables.Remove(_transactTables[_transactTables.Count - 1]);

                ResetActionResultState();

                if (OnLabelModified != null)
                    OnLabelModified(labelName, new EventArgs());
            }
            else
            {
                Clear();
            }

        }

        /// <summary>
        /// 
        /// </summary>
        private static void ResetActionResultState()
        {
            if (ErrorCount > 0)
                _actionResultState = ActionResult.Nok;
            else if (WarningCount > 0)
                _actionResultState = ActionResult.Hinweis;
            else
                _actionResultState = ActionResult.Hinweis;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="labelName"></param>
        /// <returns></returns>
        public static DataTable GetLabel(string labelName)
        {
            foreach (DataTable tbl in _transactTables)
            {
                if (tbl.TableName.Equals(labelName, StringComparison.OrdinalIgnoreCase))
                    return tbl;
            }
            return null;
        }

        #endregion LABEL TRANACTION


        /// <summary></summary>
        private static ActionResult _actionResultState = ActionResult.Ok;

        /// <summary></summary>
        private static JournalForm journalForm;

        /// <summary></summary>
        private static readonly DateTime _start = DateTime.Now;

        /// <summary></summary>
        private static string _logFullFileName = "";

        /// <summary></summary>
        public static string LogFullFileName
        {
            get { return Journal._logFullFileName; }
        }

        /// <summary></summary>
        private static int _depth = -1;

        /// <summary></summary>
        private static bool _applyLogDirExists = false;

        /// <summary></summary>
        private static DataTable _logTable;

        /// <summary></summary>
        public static DataTable LogTable { get { return Journal._logTable; } }

        /// <summary></summary>
        private static bool _enabled = true;
        /// <summary></summary>
        public static bool Enabled
        {
            get { return _enabled; }
            set { _enabled = value; if (OnActionResultEscalation != null)OnActionResultEscalation(null, null); }
        }

        /// <summary></summary>
        public static int ErrorCount { get { return _logTable.Select(COLUMNNAME_ACTIONRESULT + "='" + ActionResult.Nok.ToString() + "'").Length; } }

        /// <summary></summary>
        public static int WarningCount { get { return _logTable.Select(COLUMNNAME_ACTIONRESULT + "='" + ActionResult.Hinweis.ToString() + "'").Length; } }

        private static string _setupLogPath;
        /// <summary></summary>
        public static string SETUP_LOGS_PATH
        {
            get
            {
                try
                {
                    if (_setupLogPath == null)
                    {
                        //string path = Path.Combine(Application.StartupPath, "Logs");
                        string path =  "Logs";

                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(path);

                        _setupLogPath = path;
                    }
                }
                catch { }
                return _setupLogPath;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        static Journal()
        {
            _logTable = new DataTable();
            _logTable.Columns.Add(COLUMNNAME_TIME, Type.GetType("System.DateTime"));
            _logTable.Columns.Add(COLUMNNAME_SENDER);
            _logTable.Columns.Add(COLUMNNAME_ACTIONTYPE);
            _logTable.Columns.Add(COLUMNNAME_ACTION);
            _logTable.Columns.Add(COLUMNNAME_ACTIONRESULT);
            _logTable.Columns.Add(COLUMNNAME_COMMENTS);
            _logTable.Columns.Add(COLUMNNAME_EXCEPTION);

            journalForm = new JournalForm();

            if (!_applyLogDirExists)
            {
                if (!Directory.Exists(SETUP_LOGS_PATH))
                    Directory.CreateDirectory(SETUP_LOGS_PATH);

                _applyLogDirExists = true;
            }

            _logFullFileName = Path.Combine(SETUP_LOGS_PATH, DateTime.Now.ToString("yyyyMMdd_hhmmss_") + Path.GetFileNameWithoutExtension(System.Windows.Forms.Application.ExecutablePath).ToLower() + ".log");
        }

        /// <summary>
        /// 
        /// </summary>
        public static void Show()
        {
            Show(false);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="showFilter"></param>
        public static void Show(bool showFilter)
        {
            if (!showFilter)
            {
                journalForm.CbErrorsOnly.Checked = true;
                journalForm.CbDev.Checked = true;
                journalForm.CbSqlExecute.Checked = true;
                journalForm.CbSqlMessage.Checked = true;
                journalForm.CbSqlScript.Checked = true;
            }

            journalForm.Apply();

            journalForm.Show(showFilter);

            journalForm.Focus();
        }

        /// <summary>
        /// 
        /// </summary>
        public static void Clear()
        {
            _logTable.Rows.Clear();

            ResetActionResultState();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="actionType"></param>
        /// <param name="action"></param>
        /// <param name="actionResult"></param>
        /// <param name="comments"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        private static string Write(string sender, ActionType actionType, string action, ActionResult actionResult, string comments, string ex)
        {
            if (!Enabled)
                return "";

            DateTime time = DateTime.Now;

            string actionResultStr = actionResult.ToString();

            DataRow row = _logTable.NewRow();
            row[COLUMNNAME_TIME] = time;
            row[COLUMNNAME_SENDER] = sender;
            row[COLUMNNAME_ACTIONTYPE] = actionType;
            row[COLUMNNAME_ACTION] = action;
            row[COLUMNNAME_ACTIONRESULT] = actionResultStr;
            row[COLUMNNAME_COMMENTS] = comments;
            row[COLUMNNAME_EXCEPTION] = ex;
            _logTable.Rows.Add(row);


            string log = "";

            sender = (sender.Trim().Length > 0) ? JOURNALATTRIBUT_MODUL + "=\"" + sender + "\"" : "";
            comments = JOURNALATTRIBUT_NOTE + "=\"" + ConvertToXmlString(comments) + "\" ";
            string timeAttr = (Journal.IncludeActionTime) ? JOURNALATTRIBUT_TIME + "=\"" + time.ToString("HH:mm:ss.fff") + "\" " : "";

            if (ex.Trim().Length > 0)
            {
                log = GetTabs(_depth + 1) + string.Format("<{0} {1}=\"{2}\" {3}{4}{5}=\"{6}\" {8}>{7}</{0}>",
                    JOURNALTAG_STEP, JOURNALATTRIBUT_RESULT, actionResultStr, timeAttr, comments, JOURNALATTRIBUT_TYPE, actionType.ToString(), ex, sender);
            }
            else
            {
                log = GetTabs(_depth + 1) + string.Format("<{0} {1}=\"{2}\" {3}{4}{5}=\"{6}\" {7}/>",
                    JOURNALTAG_STEP, JOURNALATTRIBUT_RESULT, actionResultStr, timeAttr, comments, JOURNALATTRIBUT_TYPE, actionType.ToString(), sender);
            }

            Write(log);

            if (OnActionResultEscalation != null && (int)_actionResultState < (int)actionResult)
            {
                OnActionResultEscalation(sender, new ActionResultEscalationEventArgs(action, actionResult));
                _actionResultState = actionResult;
            }

            return log;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static string WriteBegin(string sender, string action)
        {
            if (!Enabled)
                return "";

            string timeAttr = (Journal.IncludeActionTime) ? JOURNALATTRIBUT_TIME + "=\"" + DateTime.Now.ToString("HH:mm:ss.fff") + "\" " : "";
            action = JOURNALATTRIBUT_NOTE + "=\"" + ConvertToXmlString(action) + "\"";

            string appVersion = "";
            if (_depth == 0)
            {
                Assembly versionInfoAssembly = Assembly.GetEntryAssembly();

                appVersion = string.Format(" {0}=\"{1}\" {2}=\"{3}\"", JOURNALATTRIBUT_SETUPAPPVERSION, versionInfoAssembly.GetName().Version, JOURNALATTRIBUT_SETUPFILEVERSION, System.Windows.Forms.Application.ProductVersion);
            }

            string log = GetTabs(_depth) + string.Format("<{0} {1} {2}{3}=\"{4}\"{5}>",
                JOURNALTAG_ACTION, action, timeAttr, JOURNALATTRIBUT_MODUL, sender, appVersion);

            Write(log);

            return log;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static string WriteEnd()
        {
            if (!Enabled)
                return "";

            if (_depth == 0)
            {
                TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - _start.Ticks);

                string resultstring = GetTabs(_depth + 1) + string.Format("<{0} {1}=\"{2}\" {3}=\"{4}\" {5}=\"{6}\"/>",
                    JOURNALATTRIBUT_SUMMARY,
                    JOURNALATTRIBUT_TOTALERRORCOUNT, ErrorCount,
                    JOURNALATTRIBUT_TOTALWARNINGCOUNT, WarningCount,
                    JOURNALATTRIBUT_TOTALRUNTIME, ((int)ts.TotalMinutes).ToString() + ":" + ts.Seconds.ToString("00"));

                Write(resultstring);
            }

            string log = GetTabs(_depth) + "</" + JOURNALTAG_ACTION + ">";

            Write(log);

            return log;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logString"></param>
        private static void Write(string logString)
        {
            if (!Journal.Enabled)
                return;

            if (!Journal.WriteLogFile)
                return;

            StreamWriter fs = null;
            try
            {
                fs = new StreamWriter(_logFullFileName, true, Encoding.UTF8);
                fs.WriteLine(logString);
                fs.Close();
            }
            catch
            {
                if (fs != null) fs.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="caption"></param>
        /// <returns></returns>
        public static string ResultMessage(string caption)
        {
            return string.Format(caption, ErrorCount, WarningCount);
        }


        #endregion STATIC METHODS AND PROPERTIES

        /// <summary></summary>
        public static bool Compress = false;

        /// <summary></summary>
        public static bool WriteLogFile = false;

        /// <summary></summary>
        public static bool IncludeSqlExecuteMessages = true;

        /// <summary></summary>
        public static bool IncludeSqlMessages = true;

        /// <summary></summary>
        public static bool IncludeActionTime = false;



        /// <summary></summary>
        private object _sender = "";
        /// <summary></summary>
        private string _action = "";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="action"></param>
        public Journal(object sender, string action)
        {
            if (!Enabled)
                return;

            _action = action;
            _sender = sender;

            Journal._depth++;

            Journal.WriteBegin(Journal.GetSenderName(_sender), _action);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="commentar"></param>
        public void Add(string commentar)
        {
            Journal.Add(_sender, _action, commentar);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        public void Add(Exception ex)
        {
            Journal.Add(_sender, _action, ex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="actionResult"></param>
        /// <param name="commentar"></param>
        public void Add(ActionResult actionResult, string commentar)
        {
            Journal.Add(_sender, _action, actionResult, commentar);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="actionResult"></param>
        /// <param name="commentar"></param>
        /// <param name="ex"></param>
        public void Add(ActionResult actionResult, string commentar, Exception ex)
        {
            Journal.Add(_sender, ActionType.Dev, _action, actionResult, commentar, ex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="commentar"></param>
        /// <param name="ex"></param>
        public void Add(string commentar, Exception ex)
        {
            Journal.Add(_sender, ActionType.Dev, _action, ActionResult.Nok, commentar, ex);
        }

    }
}
